package io.renren.modules.simida.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.simida.entity.SysDictEntity;
import io.renren.modules.simida.service.SysDictService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 数据字典表
 *
 * @author miaoguoxin
 * @email ${email}
 * @date 2019-11-22 22:09:47
 */
@RestController
@RequestMapping("simida/sysdict")
public class SysDictController {
    @Autowired
    private SysDictService sysDictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("simida:sysdict:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysDictService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("simida:sysdict:info")
    public R info(@PathVariable("id") Long id){

        return R.ok().put("sysDict", sysDictService.queryById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("simida:sysdict:save")
    public R save(@RequestBody SysDictEntity sysDict){
		sysDictService.saveOne(sysDict);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("simida:sysdict:update")
    public R update(@RequestBody SysDictEntity sysDict){
		sysDictService.updateOneById(sysDict);

        return R.ok();
    }

    /**
     * 逻辑删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("simida:sysdict:delete")
    public R delete(@RequestBody Long[] ids){
		sysDictService.logicDeleteBatch(Arrays.asList(ids));
        return R.ok();
    }

    /**
    * @Description: 查询所有字典类型
    * @Param:
    * @return:
    * @Author: miaoguoxin
    * @Date: 2019/11/22
    */
    @GetMapping("/all_dict_types")
    public R queryAllDictTypes(){
        return R.ok().put("dictType",sysDictService.queryAllDictTypes());
    }
}
